__doc__ =   """ Provides varius properties of atoms as dictionaries
                and functions.
            """

def get_united_radius(d, forgiving =True):
    """ Returns the united atom of a given atom dict.
        if forgiving is True accepts default value.
    """
    radius = UNITED_RADII.get((d['res_name'], d['at_id']))
    if not radius:
        radius = DEFAULT_UNITED_RADII.get(d['element'])
    if not radius and forgiving:
        radius = DEFAULT_UNITED_RADIUS
    return radius

def get_vdw_radius(d, forgiving =True):
    """ Returns the VdW radius for a given atom dict.
        if forgiving is True accepts default value.
    """
    radius = VDW_RADII.get(d['at_id'])
    if not radius:
        radius = VDW_RADII.get(d['element'])
    if not radius and forgiving:
        radius = DEFAULT_VDW_RADIUS
    return radius

def get_ion_radius(d, forgiving =True):
    """ Returns the ionic radius for a given atom dict.
        if forgiving is True accepts default value.
    """
    radius = ION_RADII.get(d['at_id'])
    if not radius and forgiving:
        radius = DEFAULT_ION_RADIUS
    return radius

def get_radius(d, radius_type, forgiving =True):
    """ wrapper function for specific atomic radii functions
        provides sane defaults if for an atom the corresponding
        atom radius is not found.
    """
    if d['element'] in ION_RADII:
        radius = get_ion_radius(d, forgiving)
    elif radius_type == 'united':
        radius = get_united_radius(d, forgiving)
    elif radius_type == 'vdw':
        radius = get_vdw_radius(d, forgiving)
    return radius

DEFAULT_UNITED_RADIUS = 1.8
UNITED_RADII = {
('ALA','CB') :1.95, ('ARG','NH') :1.70, ('ARG','CZ') :1.80,
('ARG','NE') :1.65, ('ARG','CD') :1.90, ('ARG','CG') :1.90,
('ASN','ND2'):1.70, ('ASN','OD1'):1.60, ('ASN','CG') :1.80,
('ASP','OD') :1.60, ('ASP','CG') :1.80, ('GLN','NE2'):1.70,
('GLN','OE1'):1.60, ('GLN','CD') :1.80, ('GLN','CG') :1.90,
('GLU','OE') :1.60, ('GLU','CD') :1.80, ('GLU','CG') :1.90,
('GLY','CA') :1.90, ('HIS','CD2'):1.90, ('HIS','NE2'):1.65,
('HIS','CE1'):1.90, ('HIS','ND1'):1.65, ('HIS','CG') :1.80,
('H_HOH','O')  :1.70, ('ILE','CD1'):1.95, ('ILE','CG1'):1.90,
('ILE','CB') :1.85, ('ILE','CG2'):1.95, ('LEU','CD') :1.95,
('LEU','CG') :1.85, ('LYS','NZ') :1.75, ('LYS','CE') :1.90,
('LYS','CD') :1.90, ('LYS','CG') :1.90, ('MET','CE') :1.95,
('MET','CG') :1.90, ('PHE','CD') :1.90, ('PHE','CE') :1.90,
('PHE','CZ') :1.90, ('PHE','CG') :1.80, ('PRO','CD') :1.90,
('PRO','CG') :1.90, ('SER','OG') :1.70, ('H_SUL','S')  :1.90,
('H_SUL','O')  :1.65, ('H_SO4','S')  :1.90, ('H_SO4','O')  :1.65,
('THR','CG2'):1.95, ('THR','OG1'):1.70, ('THR','CB') :1.85,
('TRP','CE2'):1.80, ('TRP','CE3'):1.90, ('TRP','CD1'):1.90,
('TRP','CD2'):1.80, ('TRP','CZ') :1.90, ('TRP','CH2'):1.90,
('TRP','NE1'):1.65, ('TRP','CG') :1.80, ('TYR','OH') :1.70,
('TYR','CD') :1.90, ('TYR','CE') :1.90, ('TYR','CZ') :1.80,
('TYR','CG') :1.80, ('VAL','CG') :1.95, ('VAL','CB') :1.85,
('H_WAT','O')  :1.70}

DEFAULT_UNITED_RADII = {
 ' C'  :1.80, ' N'  :1.65, ' S'  :1.90,
 ' O'  :1.60, ' P'  :1.88, 'SE'  :2.15}

DEFAULT_VDW_RADIUS = 1.80
VDW_RADII = {
 ' H'  :1.20, ' F'  :1.47, 'SE'  :1.90, ' N'  :1.55, ' O'  :1.52,
 ' C'  :1.70, ' S'  :1.80, ' P'  :1.80, 'FE'  :1.47, 'MG'  :1.73,
 'CO'  :1.25, 'MN'  :1.73, 'NA'  :2.27, 'CU'  :1.40, 'CL'  :1.75,
 ' I'  :1.97, ' B'  :1.85, 'BR'  :1.85, ' K'  :2.75, 'ZN'  :1.39,
 'HG'  :1.80, 'XE'  :1.80, 'AU'  :1.80, 'LI'  :1.80}

DEFAULT_AREAIMOL_VDW_RADIUS = 1.80
AREAIMOL_VDW_RADII = {
 ' C'  :1.80, ' N'  :1.65, ' O'  :1.60, ' S'  :1.85, ' P'  :1.90,
 'CL'  :1.80, 'CO'  :1.80, 'MG'  :1.60}

DEFAULT_ION_RADIUS = 1.0
ION_RADII = {
 'AL': 0.54, 'AS': 0.58, 'AU': 1.37, 'BA': 1.35,
 'BE': 0.45, 'BI': 1.03, 'BR': 1.96, 'CA': 1.0 ,
 'CD': 0.95, 'CL': 1.81, 'CO': 0.65, 'CR': 0.73,
 'CS': 1.67, 'CU': 0.73, ' F': 1.33, 'FE': 0.61,
 'GA': 0.62, 'GE': 0.73, 'HG': 1.02, ' I': 2.2 ,
 ' K': 1.38, 'LI': 0.76, 'MG': 0.72, 'MN': 0.83,
 'MO': 0.69, 'NA': 1.02, 'NI': 0.69, 'PB': 1.19,
 'PD': 0.86, 'PT': 0.84, 'RB': 1.52, 'SB': 0.76,
 'SC': 0.75, 'SN': 0.69, 'SR': 1.18, 'TC': 0.65,
 'TI': 0.86, ' V': 0.79, 'ZN': 0.74, 'ZR': 0.72 }

# most common values for ionic charges
ION_CHARGE = {
 ' F': '1-', ' I': '1-', ' K': '1+', ' V': '2+',
 'AL': '3+', 'AS': '3+', 'AU': '1+', 'BA': '2+',
 'BE': '2+', 'BI': '3+', 'BR': '1-', 'CA': '2+',
 'CD': '2+', 'CL': '1-', 'CO': '2+', 'CR': '2+',
 'CS': '6+', 'CU': '2+', 'FE': '2+', 'GA': '3+',
 'GE': '2+', 'HG': '2+', 'LI': '1+', 'MG': '2+',
 'MN': '2+', 'MO': '3+', 'NA': '1+', 'NI': '2+',
 'PB': '2+', 'PD': '2+', 'PT': '2+', 'RB': '1+',
 'SB': '3+', 'SC': '3+', 'SN': '4+', 'SR': '2+',
 'TC': '4+', 'TI': '2+', 'ZN': '2+', 'ZR': '4+'}

# sort atoms in resiude according to PDBv3 specification
AT_ORDER =  {'N':3, 'CA':2, 'C':1, 'O':0}
AT_REMOTE = {'A':0, 'B':1,  'G':2, 'D':3, 'E':4, 'Z':5,\
             'H':6, 'X':7,  '1':8, '2':9, 'N':9, '3':10}
                           #H1, H2, H3 and NH2 in PDV v2.3

# For amino acids, the traditional order of atom records within a residue is N, CA, C, O, followed by the
# sidechain atoms (CB, CG1, CG2 . . . ) in order first of increasing remoteness, and then branch. The extra
# oxygen at the carboxyl terminal is called " OXT", and appears after all sidechain atoms.
# EOF

#Set 1 Set 2
#(Richards, 1977) (Richmond & Richards, 1978)
#ch4 2.00 1.90
#ch3 1.70 1.70
#nh4 2.00 1.70
#nh3 1.70 1.70
#oh4 1.60 1.40
#oh3 1.50 1.40
#sh 2.00 1.80
#st 1.80 1.80
#zn 0.64 0.64
#fe 0.64 0.64

value_table = {
('ALA', ' N  '):(),
('ALA', ' CA '):(),
('ALA', ' O  '):(),
('ALA', ' C  '):(),
('ALA', ' CB '):(),
('ARG', ' N  '):(),
('ARG', ' CA '):(),
('ARG', ' O  '):(),
('ARG', ' C  '):(),
('ARG', ' NE '):(),
('ARG', ' CB '):(),
('ARG', ' CG '):(),
('ARG', ' CD '):(),
('ARG', ' CZ '):(),
('ARG', ' NH1'):(),
('ARG', ' NH2'):(),
('ASN', ' N  '):(),
('ASN', ' CA '):(),
('ASN', ' O  '):(),
('ASN', ' C  '):(),
('ASN', ' ND2'):(),
('ASN', ' CB '):(),
('ASN', ' CG '):(),
('ASN', ' OD1'):(),
('ASP', ' N  '):(),
('ASP', ' CA '):(),
('ASP', ' O  '):(),
('ASP', ' C  '):(),
('ASP', ' CB '):(),
('ASP', ' CG '):(),
('ASP', ' OD1'):(),
('ASP', ' OD2'):(),
('ASX', ' N  '):(),
('ASX', ' CA '):(),
('ASX', ' O  '):(),
('ASX', ' C  '):(),
('ASX', ' CB '):(),
('ASX', ' CG '):(),
('ASX', ' XD1'):(),
('ASX', ' XD2'):(),
('CPR', ' N  '):(),
('CPR', ' CA '):(),
('CPR', ' O  '):(),
('CPR', ' C  '):(),
('CPR', ' CB '):(),
('CPR', ' CG '):(),
('CPR', ' CD '):(),
('CYH', ' N  '):(),
('CYH', ' CA '):(),
('CYH', ' O  '):(),
('CYH', ' C  '):(),
('CYH', ' CB '):(),
('CYH', ' SG '):(),
('CYS', ' N  '):(),
('CYS', ' CA '):(),
('CYS', ' O  '):(),
('CYS', ' C  '):(),
('CYS', ' CB '):(),
('CYS', ' SG '):(),
('GLN', ' N  '):(),
('GLN', ' CA '):(),
('GLN', ' O  '):(),
('GLN', ' C  '):(),
('GLN', ' CB '):(),
('GLN', ' CG '):(),
('GLN', ' CD '):(),
('GLN', ' NE2'):(),
('GLN', ' OE1'):(),
('GLU', ' N  '):(),
('GLU', ' CA '):(),
('GLU', ' O  '):(),
('GLU', ' C  '):(),
('GLU', ' CB '):(),
('GLU', ' CG '):(),
('GLU', ' CD '):(),
('GLU', ' OE2'):(),
('GLU', ' OE1'):(),
('GLX', ' N  '):(),
('GLX', ' CA '):(),
('GLX', ' O  '):(),
('GLX', ' C  '):(),
('GLX', ' CB '):(),
('GLX', ' CG '):(),
('GLX', ' CD '):(),
('GLX', ' XE2'):(),
('GLX', ' XE1'):(),
('GLY', ' N  '):(),
('GLY', ' CA '):(),
('GLY', ' O  '):(),
('GLY', ' C  '):(),
('HIS', ' N  '):(),
('HIS', ' CA '):(),
('HIS', ' O  '):(),
('HIS', ' C  '):(),
('HIS', ' CD2'):(),
('HIS', ' CB '):(),
('HIS', ' CG '):(),
('HIS', ' CE1'):(),
('HIS', ' ND1'):(),
('HIS', ' NE2'):(),
('ILE', ' N  '):(),
('ILE', ' CA '):(),
('ILE', ' O  '):(),
('ILE', ' C  '):(),
('ILE', ' CB '):(),
('ILE', ' CD '):(),
('ILE', ' CD1'):(),
('ILE', ' CG1'):(),
('ILE', ' CG2'):(),
('LEU', ' N  '):(),
('LEU', ' CA '):(),
('LEU', ' O  '):(),
('LEU', ' C  '):(),
('LEU', ' CB '):(),
('LEU', ' CG '):(),
('LEU', ' CD1'):(),
('LEU', ' CD2'):(),
('LYS', ' N  '):(),
('LYS', ' CA '):(),
('LYS', ' O  '):(),
('LYS', ' C  '):(),
('LYS', ' NZ '):(),
('LYS', ' CB '):(),
('LYS', ' CG '):(),
('LYS', ' CE '):(),
('LYS', ' CD '):(),
('MET', ' N  '):(),
('MET', ' CA '):(),
('MET', ' O  '):(),
('MET', ' C  '):(),
('MET', ' CB '):(),
('MET', ' CG '):(),
('MET', ' CE '):(),
('MET', ' SD '):(),
('MSE', ' N  '):(),
('MSE', ' CA '):(),
('MSE', ' O  '):(),
('MSE', ' C  '):(),
('MSE', ' CB '):(),
('MSE', ' CG '):(),
('MSE', ' CE '):(),
('MSE', ' SD '):(),
('MSE', 'SE  '):(),
('PHE', ' N  '):(),
('PHE', ' CA '):(),
('PHE', ' O  '):(),
('PHE', ' C  '):(),
('PHE', ' CD2'):(),
('PHE', ' CB '):(),
('PHE', ' CG '):(),
('PHE', ' CZ '):(),
('PHE', ' CD1'):(),
('PHE', ' CE1'):(),
('PHE', ' CE2'):(),
('PRO', ' N  '):(),
('PRO', ' CA '):(),
('PRO', ' O  '):(),
('PRO', ' C  '):(),
('PRO', ' CB '):(),
('PRO', ' CG '):(),
('PRO', ' CD '):(),
('SEM', ' N  '):(),
('SEM', ' CA '):(),
('SEM', ' O  '):(),
('SEM', ' C  '):(),
('SEM', ' CB '):(),
('SEM', ' CG '):(),
('SEM', ' CE '):(),
('SEM', ' SD '):(),
('SEM', 'SE  '):(),
('SER', ' N  '):(),
('SER', ' CA '):(),
('SER', ' O  '):(),
('SER', ' C  '):(),
('SER', ' OG '):(),
('SER', ' CB '):(),
('THR', ' N  '):(),
('THR', ' CA '):(),
('THR', ' O  '):(),
('THR', ' C  '):(),
('THR', ' CB '):(),
('THR', ' OG1'):(),
('THR', ' CG2'):(),
('TRP', ' N  '):(),
('TRP', ' CA '):(),
('TRP', ' O  '):(),
('TRP', ' C  '):(),
('TRP', ' CZ2'):(),
('TRP', ' CZ3'):(),
('TRP', ' CD1'):(),
('TRP', ' CD2'):(),
('TRP', ' CH2'):(),
('TRP', ' CB '):(),
('TRP', ' CG '):(),
('TRP', ' CE3'):(),
('TRP', ' CE2'):(),
('TRP', ' NE1'):(),
('TYR', ' N  '):(),
('TYR', ' CA '):(),
('TYR', ' O  '):(),
('TYR', ' C  '):(),
('TYR', ' CD2'):(),
('TYR', ' OH '):(),
('TYR', ' CB '):(),
('TYR', ' CG '):(),
('TYR', ' CZ '):(),
('TYR', ' CD1'):(),
('TYR', ' CE1'):(),
('TYR', ' CE2'):(),
('UNK', ' N  '):(),
('UNK', ' CA '):(),
('UNK', ' O  '):(),
('UNK', ' C  '):(),
('VAL', ' N  '):(),
('VAL', ' CA '):(),
('VAL', ' O  '):(),
('VAL', ' C  '):(),
('VAL', ' CB '):(),
('VAL', ' CG1'):(),
('VAL', ' CG2'):(),
('XAA', ' N  '):(),
('XAA', ' CA '):(),
('XAA', ' O  '):(),
('XAA', ' C  '):()
}


























